package com.example.mydy;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import okhttp3.OkHttpClient;

public class MyRetrofitClient {
    // 这里的BASE_URL要根据你的实际后端接口地址来设置
    private static final String BASE_URL = "http://106.52.82.133:3000/";
    private static Retrofit retrofit;

    // 提供一个静态方法来获取Retrofit实例
    public static Retrofit getClient() {
        if (retrofit == null) {
            // 创建OkHttpClient实例，你可以在这里设置连接超时、读取超时等参数
            OkHttpClient client = new OkHttpClient.Builder()
                    .connectTimeout(60, java.util.concurrent.TimeUnit.SECONDS)
                    .readTimeout(60, java.util.concurrent.TimeUnit.SECONDS)
                    .writeTimeout(60, java.util.concurrent.TimeUnit.SECONDS)
                    .build();

            // 使用Retrofit.Builder构建Retrofit实例，设置基础URL和Gson转换器
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(client)
                    .build();
        }
        return retrofit;
    }
}